function h = H(p)
   if(p == 0 || p == 1)
       h = 0;
   elseif(p == inf)
       h = 100000;
   elseif(isnan(p)) %if p = 0/0
       h = 0;
   else
       h = -p*log2(p) - (1-p)*log2(1-p);
   end
end